package org.ilc;

import org.ilc.util.DateUtils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author malongbo
 * @time 13-7-12 下午11:48
 */
public class FileLogger {
    private final String logFileName = "system.log";
    private String logFile = null;

    public FileLogger() {
        this.logFile = Bootstrap.getContext().getLogDir().concat(File.separator).concat(logFileName);
//        this.logFile = "d:/".concat(File.separator).concat(logFileName);
    }

    public void log(Class clazz,String content) {
        String nowTime = DateUtils.getNowTime();

        String clazzName = clazz.getName();

        String log = nowTime + " [" + clazzName + "] - " + content + "\r\n";

        FileWriter fw = null;

        try {
            fw = new FileWriter(logFile, true);
            fw.write(log);
        } catch (IOException e) {
            System.out.println("书写日志错误：" + e.getMessage());
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (IOException e) {

                }
            }
        }
    }
/*
    public static void main(String[] args) {
        new FileLogger().log(FileLogger.class, "记录日志");
    }*/
}
